import 'babel-polyfill'
import Vue from 'vue'
import 'amfe-flexible'
import Vant from 'vant'
import 'vant/lib/index.css'
import 'normalize.css/normalize.css'// A modern alternative to CSS resets
import '@/assets/css/index.scss' // global css

import App from './App'
import router from './router'
import store from './store'
import fastclick from 'fastclick'
import VueLazyLoad from 'vue-lazyload'

import * as filters from './base/filters' // global filters
Vue.use(Vant)
fastclick.attach(document.body)
fastclick.prototype.focus = function(targetElement) {
  var length
  if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month' && targetElement.type !== 'email') {
    length = targetElement.value.length
    targetElement.setSelectionRange(length, length)
    targetElement.focus()
  } else {
    targetElement.focus()
  }
}

window.addEventListener('focusout', function() {
  // 软键盘收起的事件处理
  window.scrollTo(0, 0)
  setTimeout(() => {
    console.log('focusout')
    window.scrollTo(0, 0)
    // window.scrollTo(0, document.documentElement.scrollTop || document.body.scrollTop)
  }, 100)
})

/* eslint-disable no-unused-vars */
// import vConsole from 'vconsole'

Vue.use(VueLazyLoad, {
  loading: require('@/assets/images/default.png')
})
Vue.prototype._loadError = function(e) {
  e.target.src = require('@/assets/images/hailang/error_img.png')
}
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
